set more off

/*Probability graphs - to be loaded after modell.do or replication.do*/
/*Unemployment: 4.4;19, Median 9.4, IQV: 7.7-11
Growth -.9; 4.6, Median 1.9, IQV .9-2.5*/

  
/*   Moderate Left */

  
est restore left

/*Average departmental effects?*/
  local averagedep = 96 * _b[_cons]
/* 95 Deviations from Department 1 (the constant)*/
  forvalues d= 1/95 {
    local averagedep = `averagedep' + _b[_x_`d']
  }

local leftaveragedep = `averagedep' / 96

est restore right

/*Average departmental effects?*/
  local averagedep = 96 * _b[_cons]
/* 95 Deviations from Department 1 (the constant)*/
  forvalues d= 1/95 {
    local averagedep = `averagedep' + _b[_x_`d']
  }

local rightaveragedep = `averagedep' / 96

est restore kommunist

/*Average departmental effects?*/
  local averagedep = 96 * _b[_cons]
/* 95 Deviations from Department 1 (the constant)*/
  forvalues d= 1/95 {
    local averagedep = `averagedep' + _b[_x_`d']
  }

local kommunistaveragedep = `averagedep' / 96

est restore fn

/*Average departmental effects?*/
  local averagedep = 96 * _b[_cons]
/* 95 Deviations from Department 1 (the constant)*/
  forvalues d= 1/95 {
    local averagedep = `averagedep' + _b[_x_`d']
  }

local fnaveragedep = `averagedep' / 96

est restore rest

/*Average departmental effects?*/
  local averagedep = 96 * _b[_cons]
/* 95 Deviations from Department 1 (the constant)*/
  forvalues d= 1/95 {
    local averagedep = `averagedep' + _b[_x_`d']
  }

local restaveragedep = `averagedep' / 96



/*Scenarios: Low (.9), Medium (1.9), High (2.5) Growth
Unemployment 6.5-12.9% (10% percentile to 90% percentile),
Left incumbent yes/no*/

  /*Create data set for plotting*/
  clear
/*unemployment range*/
set obs 65
gen unemployment =65
replace unemployment = unemployment[_n-1]+1 in 2/65
replace unemployment=unemployment/10

save unempl,replace

/*3 Levels of growth*/
clear
set obs 3
gen growth = .9
replace growth =1.9 in 2
replace growth = 2.5 in 3

save growth,replace

/*Incumbency yes/no*/

  clear
set obs 2
gen incumbency=0
replace incumbency =1 in 2
save inc,replace

/*Cross them*/
  use unempl
cross using growth
cross using inc


/*Predict vote shares on the  scale*/
foreach model in left right kommunist fn rest { 

  est restore `model'
  gen pr`model'logit = ``model'averagedep' + unemployment*_b[unempfr] + incumbency*_b[incleft] + incumbency*unemployment*_b[incleftXunempfr] + growth*_b[natgrowth]

  /*Convert to odds*/
  gen pr`model'odds= exp(pr`model'logit)
}

/*Calculate expected share of nonvoters (per cent)*/
  egen divisor = rowtotal(pr*odds)
replace divisor = divisor +1
gen prnonv = 100 / divisor

foreach model in left right kommunist fn rest { 
  gen pr`model' = (pr`model'odds * 100) /divisor
}

/*Prepare Graphs*/
/*Labels require integers*/

recode growth (.9=1) (1.9=2) (2.5=3)
lab define growth 1 "Low Growth (0.9)" 2 "Medium Growth (1.9)" 3 "High Growth (2.5)"
lab val growth growth

set scheme sj
	
	graph twoway (line prleft unemployment if incumbency ==0 & growth==2) (line prleft unemployment if incumbency ==1 & growth==2), ytitle("Mod Left support") legend(off) xtitle("")
/* 	legend(label(1 "Left Incumbency: no") label(2 "Left Incumbency: yes")) */

graph save left,replace


	graph twoway (line prright unemployment if incumbency ==0 & growth==2) (line prright unemployment if incumbency ==1 & growth==2), ytitle("Mod Right support") legend(off) xtitle("")
	/* legend(label(1 "Left Incumbency: no") label(2 "Left Incumbency: yes")) */

graph save right,replace


graph twoway (line prkommunist unemployment if incumbency ==0 & growth==2) (line prkommunist unemployment if incumbency ==1 & growth==2), ytitle("Communist support") xtitle("")	legend(off) /* legend(label(1 "Left Incumbency: no") label(2 "Left Incumbency: yes")) */

graph save communist,replace


graph twoway (line prfn unemployment if incumbency ==0 & growth==2) (line prfn unemployment if incumbency ==1 & growth==2), ytitle("FN support") xtitle("")	legend(off) /* legend(label(1 "Left Incumbency: no") label(2 "Left Incumbency: yes")) */

graph save fn,replace



graph twoway (line prrest unemployment if incumbency ==0 & growth==2) (line prrest unemployment if incumbency ==1 & growth==2), ytitle("Other support") xtitle("")	legend(off) /*  legend(label(1 "Left Incumbency: no") label(2 "Left Incumbency: yes")) */

graph save rest,replace


	graph twoway (line prnonv unemployment if incumbency ==0 & growth==2) (line prnonv unemployment if incumbency ==1 & growth==2), ytitle("Nonvoters") xtitle("")	legend(off)
	/* legend(label(1 "Left Incumbency: no") label(2 "Left Incumbency: yes")) */

graph save nonv,replace

	/*Combine graphs*/
	graph combine left.gph right.gph nonv.gph fn.gph communist.gph rest.gph,rows(2) scheme(sj) note("Dashed line: incumbent left-wing government, solid line: incumbent right-wing government. National GDP growth held constant at 1.9 per cent",size(vsmall))

	graph export voting.emf,replace
